package com.coderli.onecoder.server.handler;

import org.jboss.netty.channel.MessageEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.coderli.onecoder.shared.model.AgentInfo;
import com.coderli.onecoder.shared.model.Command;
import com.coderli.onecoder.shared.model.CommandRequest;


/**
 * @author lihzh
 * @date 2012-7-6 下午3:26:36
 */
public class AgentInfoHandler implements AgentMessageHandler {
	
	private static final Logger log = LoggerFactory.getLogger(AgentInfoHandler.class);

	@Override
	public void handleMessage(MessageEvent event) {
		log.info("Begin to handle agent info.");
		AgentInfo info = (AgentInfo) event.getMessage();
		log.info(info.getAliaName());
		log.info(info.getAgentIp());
		// TODO 如果数据库中没有此Agent，则存入数据库，如果有，则取更此Agent相关的信息, HypervisorConnection
		// TODO 发送事件，告之Agent处理结束。发命令让Agent启动线程开始探测。
		 createInitRequest();
	}
	
	private CommandRequest createInitRequest() {
		CommandRequest request = new CommandRequest();
		Command command = new Command(Command.Type.INIT);
		request.setCommand(command);
		return request;
	}


}
